

package com.xiuluo.dubbotest.service.impl;

import com.alibaba.fastjson.JSON;
import com.xiuluo.dubbotest.common.utils.RedisKeyUtil;
import com.xiuluo.dubbotest.dao.CacheDao;
import com.xiuluo.dubbotest.model.po.CachePO;
import com.xiuluo.dubbotest.model.po.UserPO;
import com.xiuluo.dubbotest.service.CacheService;
import com.xiuluo.dubbotest.service.RedisService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author idea
 * @date 2020/2/26
 * @version V1.0
 */
@Service
public class CacheServiceImpl implements CacheService {

    @Resource
    private CacheDao cacheDao;

    @Override
    public Integer saveCache(String key, Object value)
    {
        String json = JSON.toJSONString(value);
        return cacheDao.saveCache(key,json);
    }

    @Override
    public <T> T getCache(String key,Class<T> clazz)
    {
        CachePO cache = cacheDao.getCache(key);
        String value = cache.getValue();
        T obj = JSON.parseObject(value, clazz);
        return obj;
    }
}
